package com.example.demo.day0229;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;

/**
 * 字符流只适合操作字符文件
 */
public class CopyFile1 {
        public static void copyFile (String inPath, String outPath) {
            try {
                FileReader fr = new FileReader(inPath);
                FileWriter fw = new FileWriter(outPath);

                char[] c = new char[100];

                int len = 0;
                while((len = fr.read(c)) != -1){//直到br.read执行到没有字符串，此时返回值为-1。不再读取文件
                    fw.write(c,0,len);//将数据写到内存
                }
                fw.flush();//将内存的数据刷到硬盘上
                fr.close();
                fw.close();//关闭两个流
            } catch (Exception e) {
                e.printStackTrace();
            }


    }
}
